﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DTO;
using QLBH.Model.Controller;
using QLBH.DataModel;

namespace Module.Category.BL
{
    public class CustomerManagementBL
    {
        private static CustomerManagementBL instance;

        public static CustomerManagementBL Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CustomerManagementBL();
                }
                return instance;
            }
        }
        public CustomerManagementBL()
        {

        }
        /// <summary>
        /// Get All Customer
        /// </summary>
        /// <returns></returns>
        public IList<KhachHangDTO> GetAllCustomers()
        {
            IList<KhachHang> customs = CustomerController.Instance.GetAll().ToList();
            return KhachHangAssembler.ToDTOs(customs).ToList();
        } 
        /// <summary>
        /// add new customer
        /// </summary>
        /// <returns></returns>
        public bool AddCustomer(KhachHangDTO newCustomer)
        {
            try
            {
                KhachHang customer = KhachHangAssembler.ToEntity(newCustomer);
                CustomerController.Instance.Add(customer);
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }
        /// <summary>
        /// Update Customer object 
        /// </summary>
        /// <param name="updateCustomer"></param>
        /// <returns></returns>
        public bool UpdateCustomer(KhachHangDTO updateCustomer)
        {
            try
            {
                KhachHang customer = KhachHangAssembler.ToEntity(updateCustomer);
                CustomerController.Instance.Edit(customer);
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Delete Customers
        /// </summary>
        /// <param name="listCustomers"></param>
        /// <returns></returns>
        public bool DeleteCustomers(IList<KhachHangDTO> listCustomers)
        {
            try
            {
                ICollection<KhachHang> customers = KhachHangAssembler.ToEntities(listCustomers);
                CustomerController.Instance.Deletes(customers.ToList());
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            

        }
    }
}
